<template>
	<view class="tab_bar">
		<view class="tabbarBox">
			<view class="handleBox" v-for="(item,index) in tabBarList" :key="index">
				<view class="menuBox" @click="goPages(item.pagePath)">
					<view class="menuIcon">
						<image v-if="item.pagePath!=selectIndex" class="img" :src="item.iconPath"></image>
						<image v-else class="img" :src="item.selectedIconPath"></image>
					</view>
					<view class="menuName">
						<text :class="item.pagePath==selectIndex?'TextColor':'Text'">{{item.text}}</text>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		props: {
			page: {
				type: String,
				default: "/pages/index/index"
			},
			status: {
				type: Number,
				default: 2
			}
		},
		watch: {
			page: {
				handler(value) {
					this.selectIndex = value;
				},
				immediate: true,
				deep: true
			}
		},
		data() {
			return {
				selectIndex: "",
				tabBarList: "",
			}

		},
		//uniapp子组件不支持应用生命周期，所以只能用vue生命周期
		created() {
			if (this.$props.status == 2) {
				//tabbar数据，这儿也支持后台定义通过接口获取数据
				this.tabBarList = [{
					"text": "首页",
					"pagePath": "/pages/index/index",
					"iconPath": "/static/tabber/index.png",
					"selectedIconPath": "/static/tabber/index-active.png"
				}, {
					"text": "消息",
					"pagePath": "/pages/success/success",
					"iconPath": "/static/tabber/success.png",
					"selectedIconPath": "/static/tabber/success-active.png"
				}, {
					"text": "个人中心",
					"pagePath": "/pages/user/user",
					"iconPath": "/static/tabber/user.png",
					"selectedIconPath": "/static/tabber/user-active.png"
				}]
			} else {
				//tabbar数据，这儿也支持后台定义通过接口获取数据
				this.tabBarList = [{
					"text": "首页",
					"pagePath": "/pages/index/index",
					"iconPath": "/static/tabber/home.png",
					"selectedIconPath": "/static/tabber/home-active.png"
				}, {
					"text": "我的",
					"pagePath": "/pages/user/user",
					"iconPath": "/static/tabber/my.png",
					"selectedIconPath": "/static/tabber/my-active.png"
				}]
			}

		},
		methods: {
			//进入tabble页
			goPages(pagePath) {
				uni.switchTab({
					url: pagePath
				})
			},

		},
	}
</script>
<style lang="scss">
	.tab_bar {
		width: 100vw;
		position: fixed;
		left: 0;
		bottom: 0;
		background: #fff;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		box-shadow: 0 0 30rpx -10rpx #ccc;

		.tabbarBox {
			display: flex;
			margin-top: 10rpx;
			justify-content: space-evenly;


			.handleBox {
				width: 20vw;

				.menuBox {
					padding: 0rpx 20rpx;
					width: 120rpx;
					height: 98%;
					text-align: center;

					.img {
						width: 50rpx;
						height: 50rpx;
					}
				}
			}
		}
	}

	.Text {
		font-size: 24rpx;
		font-family: Cochin, serif;
		font-weight: 900;
		color: #C4C4C4;
	}

	.TextColor {
		@extend .Text;
		color: #2558FB;
	}
</style>